import random
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep


op = webdriver.ChromeOptions()
op.add_experimental_option('excludeSwitches', ['enable-automation'])
op.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome(options=op)
driver.get("https://www.baidu.com")
sleep(2)

input_text = driver.find_element(By.CSS_SELECTOR, "#kw")
input_text.send_keys("自动化")

ran = random.randint(0, 10)
for i in range(ran):
    input_text.send_keys(Keys.DOWN)
    sleep(1)

search_text = input_text.get_attribute('value')
input_text.send_keys(Keys.ENTER)
sleep(2)

new_page_title = driver.title
sleep(2)

assert search_text in new_page_title

driver.quit()
